; //dialog
(function() {
    Vue.component('m-dialog', {
        template: '#dialog',
        props: ['msg'],
        methods: {
            eClick: function() {
                this.$emit('eclick');
            }
        }
    })
})();


; //init
(function() {
    new Vue({
        el: '#app',
        data: {
            isLoadingShow: 1, //loading的渲染开关
            userlist: [{
                username: 'a',
                join_time: '2016年11月5日21:27:13'
            }, {
                username: 'a',
                join_time: '2016年11月5日21:27:13'
            }, {
                username: 'a',
                join_time: '2016年11月5日21:27:13'
            }, ],
            wait_to_send: 0,
            notLoad: 1, //加载按钮禁止状态
            page: 1,
            sendData: '',
            alert: ''
        },
        methods: {
            eLoadMore: function() {
                if (this.notLoad) {
                    return
                }
                this.page++;
                this.$http({
                    url: '../main/memberlist',
                    methods: 'GET',
                    params: {
                        page_no: this.page
                    }
                }).then(function(r) {
                    return r.json()
                }).then(function(r) {
                    console.log(r);
                    this.userlist = this.userlist.concat(r.result);
                    this.wait_to_send = r.count;
                    if (this.page >= r.total_page) {
                        this.notLoad = 1;
                    }
                })
            },
            eSub: function() {
                if (!this.sendData) {
                    return this.alert = '你混弄本小姐是不是！？</br>你什么都没写啊喂！';
                }
                var vm = this;
                $.post({
                    url: '../main/send',
                    method: 'post',
                    data: {
                        msg: escape(this.sendData),
                        community_id: community_id
                    },
                    async: true,
                    success: function(r) {
                        if (r.status) {
                            vm.alert = '哼~,本小姐帮你发完了呢！（快夸我快夸我快夸我）'
                        }
                        vm.alert = '那。。。那个。。。好像搞砸了呢。。。</br>稍后再试一试吧'
                    }

                })
            },
            eSave: function() {
                if (!window.localStorage) {
                    return this.alert = '哼，你这渣渣!</br>用着渣渣的浏览器也想使用本小姐的模板功能！？</br>洗洗睡吧！';
                }
                if (this.sendData == '') {
                    return this.alert = '你。。。你。。。你什么内涵都没有</br>就想在本小姐体。。。体内。。。留下记忆！？';
                }
                localStorage.setItem(community_id, this.sendData);
                this.alert = '很好，本小姐记住了！';
            },
            eGet: function() {
                if (!window.localStorage) {
                    return this.alert = '哼，你这渣渣!</br>用着渣渣的浏览器也想使用本小姐的模板功能！？</br>洗洗睡吧！';
                }
                var data = localStorage[community_id];
                if (data) {
                    return this.sendData = data;
                }
                this.alert = '本。。。本。。。本小姐不记得</br>你给我留。。。留。。。留下过什么。。。';
            },
            eDialogClick: function() {
                this.alert = '';
            }
        },
        mounted: function() {
            this.alert = '<p>你好，我是群发娘</p><p>欢迎使用我的群发功能！</p><p>当前版本是v0.1</p>'
            this.$http({
                url: '../main/new.member.get',
                methods: 'GET',
                params: {
                    community_id: community_id
                }
            }).then(function(r) {
                return r.json()
            }).then(function(r) {
                console.log(r);
                this.isLoadingShow = 0;
                this.userlist = r.result;
                this.wait_to_send = r.count;
                if (r.total_page > 1) {
                    this.notLoad = 0;
                }
            });
        }
    })
})();